package com.lpf.iterator;

// 具体聚合 - 书架
class BookShelf implements Aggregate {
    private String[] books;
    private int last = 0;

    public BookShelf(int max) {
        this.books = new String[max];
    }

    public void appendBook(String book) {
        if (last < books.length) {
            books[last++] = book;
        }
    }

    public String getBookAt(int index) {
        return books[index];
    }

    public int getLength() {
        return last;
    }

    @Override
    public Iterator createIterator() {
        return new BookShelfIterator(this);
    }
}
